using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

using APJUtil = APJ.Util;

namespace MTRC.ODMS.Web.SOM.GeneralEvent
{
    /// <summary>
    /// Author:zengshunbo 2009-01-13.
    /// </summary>
    public partial class GeneralEventDownloadAttachment : BasePage_SOM
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //comment by jack 20151104 for u231
            //System.Collections.Specialized.NameValueCollection nv = HttpUtility.ParseQueryString(Request.Url.Query, System.Text.Encoding.Default);
            //string FilePath = nv["filePath"];
            //string FilePath = Request.RawUrl.Substring(Request.RawUrl.IndexOf("=")+1);
            string FilePath = Server.UrlDecode(Request.QueryString["filePath"].Trim().ToString());

            if (String.IsNullOrEmpty(FilePath))
            {
                Response.End();
                return;
            }
            //comment by jack 20151104 for u231
            //FilePath = APJUtil.Utility.ConvertFromBase64(FilePath);
            if (!File.Exists(FilePath))
            {
                Response.End();
                return;
            }

            if (File.Exists(FilePath))
            {
                FileInfo fi = new FileInfo(FilePath);
                Response.Clear();
                Response.ClearHeaders();
                //Response.HeaderEncoding = System.Text.Encoding.Default; //comment by jack 20151104 for u231
                Response.HeaderEncoding = System.Text.Encoding.UTF8;   
                Response.Buffer = false;
                //Response.ContentType = APJ.Util.Utility.GetContentType(Extention);
                //Response.AppendHeader("Content-Disposition", "attachment;filename=" + fi.Name);//comment by jack 20151104 for u231
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fi.Name, System.Text.Encoding.UTF8));
                Response.AppendHeader("Content-Length", fi.Length.ToString());
                Response.WriteFile(fi.FullName);
                Response.Flush();
                Response.Close();
            }
            else
            {
            }
        }
    }
}
